package info.sean.main;

import info.sean.entity.Price;
import info.sean.util.DateUtil;
import info.sean.util.IdNoUtil;
import info.sean.util.ServiceUtil;
import org.apache.commons.lang3.time.DateUtils;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class TestPropertyDescriptor {

    public static void main(String[] args) {
        try {
            Class aClass = Class.forName("info.sean.entity.Price");
            Object newInstance = aClass.newInstance();
            Field[] declaredFields = aClass.getDeclaredFields();
            for (Field declaredField : declaredFields) {
                PropertyDescriptor propertyDescriptor = new PropertyDescriptor(declaredField.getName(), aClass);
                Method writeMethod = propertyDescriptor.getWriteMethod();  //这是设置值
                writeMethod.invoke(newInstance,"100");
                System.out.println("newInstance.toString() = " + newInstance.toString());
            }
        } catch (InstantiationException | IllegalAccessException | IntrospectionException | InvocationTargetException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
class TestPropertyDescriptorReadMethod{

    public static void main(String[] args) {
        Price price = new Price();
        price.setMBuyPrice("5000元");
        System.out.println("price = " + price);
        System.out.println("\"-------------\" = " + "-------------");

        try {
            PropertyDescriptor propertyDescriptor = new PropertyDescriptor("mBuyPrice", price.getClass());
            Method readMethod = propertyDescriptor.getReadMethod();  // 获取方法，可以反射获取值
            Object invoke = readMethod.invoke(price);
            System.out.println("invoke = " + invoke);
            System.out.println("invoke.toString() = " + invoke.toString());
        } catch (IntrospectionException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }


    }




}
class TestIdNo{

    public static void main(String[] args) {
        String ID = "342601199711157144";
        String genderFromIdNo = IdNoUtil.getGenderFromIdNo(ID);
        System.out.println("性别为 = " + genderFromIdNo);

        Date birthdayFromIdNo = IdNoUtil.getBirthdayFromIdNo(ID);
        System.out.println("birthdayFromIdNo = " + birthdayFromIdNo);
        String dateString = DateUtil.getDateString(birthdayFromIdNo);
        System.out.println("生日为：" + dateString);
        int day = birthdayFromIdNo.getDay();
        System.out.println("day = " + day);

        /**
         * 验证身份证
         */
        boolean validateIdNo = ServiceUtil.validateIdNo(ID);
        System.out.println("validateIdNo = " + validateIdNo);


    }



}
class testsms{
    public static void main(String[] args) throws ParseException {

        Date sysDate = new Date();
        System.out.println("sysDate1 = " + sysDate);
        String occurDate = "2022-04-07 15:30:00";

       Date occurDateS = DateUtils.parseDate(occurDate,"yyyy-MM-dd HH:mm:ss");
        System.out.println("occurDateS = " + occurDateS);
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
        if (occurDateS != null) {
            sysDate = DateUtils.truncate(sysDate, Calendar.HOUR_OF_DAY);
            System.out.println("sysDate2 = " + sysDate);
        } else {
            sysDate = DateUtils.truncate(occurDateS, Calendar.HOUR_OF_DAY);
            System.out.println("sysDate3 = " + sysDate);
        }
        System.out.println("sysDate4 = " + sysDate)
        ;
        String sysDateTime = format.format(sysDate);
        System.out.println("sysDateTime = " + sysDateTime);
    }




}

class testpage {

    public static void main(String[] args) {
        List<Integer> deleteIds = new ArrayList<>();
        deleteIds.add(833);
        deleteIds.add(857);
        deleteIds.add(438);
        deleteIds.add(676);
        deleteIds.add(368);
        deleteIds.add(471);
        deleteIds.add(543);
        deleteIds.add(258);
        deleteIds.add(165);
        deleteIds.add(632);
        deleteIds.add(070);
        deleteIds.add(939);
        deleteIds.add(413);
        deleteIds.add(003);
        int count = 0;
        for (int i = 0; i < deleteIds.size(); i += 3) {
            count += 3;
            if (count > deleteIds.size()) {
                count = deleteIds.size();
            }
            List<Integer> subList = deleteIds.subList(i, count);
            System.out.println("subList = " + subList);
        }

    }
}


class CherryPick {

    public static void main(String[] args) {


    }
}